<?php

require('includes/head.php'); # Header stuff
require('includes/config.php'); # Misc config variables
require('includes/ppl_classes.php');

# Look for some GET data
if (isset($_REQUEST["viewtype"])){ #Was any GET string tacked on to the URL?
	$view = $_REQUEST["viewtype"];
	$query = "select * from people where dept_id = $view ORDER BY lastname";
	} else {
	$query = "select * from people ORDER BY lastname";
	}
# The "Show All" link: only if needed.
if ($view == ""){
	$showlink = "";
	} else {
	$showlink = "<a href=\"http://backserv/coop-people/\">Show Everybody</a><br />";
	}
print $showlink;


mysql_connect($hostname, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

# Populate deptartment names array

$dept_query = "select dept_name from depts;";
$dept_result = mysql_query($dept_query) or die(mysql_error());;
$numdepts = mysql_num_rows($dept_result);
$numdepts--;
for ($i=0; $i<=$numdepts; $i++){ # For each of the depts, do...
	
	$dept_row = mysql_fetch_array($dept_result);
	$deptlist[$i] = $dept_row[0];	
	}
# END dept names bit

$result = mysql_query($query) or die(mysql_error());;
$numrows=mysql_num_rows($result);
$numrows--;
#for ($i=0; $i<=$numrows; $i++){ # For each of the rows, do...


	$row = mysql_fetch_array($result);
	
	# Assign variable values from query
	$idnum = $row[0];
	$firstname = $row[1];
	$lastname = $row[2];
	$title = $row[4];
	$dept = $row[5];

	# This bit makes rows of four
	#if ($i % 4 ==0){
	#$cell_top = "<tr><td>\n";
	#$cell_bottom = "</td>\n";
	#} else {
	#$cell_top = "<td>\n";
	#$cell_bottom = "</td>\n";
	#}

	$thisperson = new profile($idnum,$dept,$firstname,$lastname,$title);
    #print $thisperson;
	#} #END of stuff for a given row
require ('includes/foot.php'); # Page footer

?>